@extends('admin.inc.base')
@section('content')
    <div style="padding:5px 0 10px 0;">当前推荐位：<b style="color:red">{{$recommend->title}}</b>&nbsp;推荐位标志：<b style="color:red">{{$recommend->position}}</b></div>
    <table class="table">
        <tr>
            <th>序号</th>
            <th>标题</th>
            <th>创建时间</th>
            <th>更新时间</th>
            <th>操作</th>
        </tr>
        @foreach($data as $key => $post)
            <tr>
                <td>{{ $key }}</td>
                <td>{{ $post -> title }}</td>
                <td>{{ $post -> created_at }}</td>
                <td>{{ $post -> updated_at }}</td>
                <td>
                    @if(in_array($post->id,$recommend->assoc))
                        <a href="javascript:;" style="color:red;">已加入推荐位</a>
                    @else
                        <a data-postid = "{{$post->id}}" data-recid="{{$recommend->id}}" class="addto" >加入到当前推荐位</a>
                    @endif
                </td>
            </tr>
        @endforeach
    </table>

    <script type="text/javascript">
        $(function(){
            $(".addto").click(function(){
                var postId=$(this).data('postid');
                var recId=$(this).data('recid');
                var that = this;
                $.get('/admin/recommend/{{$recommend->id}}/appendAction/'+postId,function(data){
                    alert(data.message);
                    if(data.state=='ok'){
                        $(that).css("color","red");
                        $(that).html("已加入推荐位");
                    }
                },'JSON');
            });
        })
    </script>
@endsection